Developer Documentation

QuickTime 4 API Documentation

Inside Macintosh: Sound

| Previous | Chapter contents | Chapter top | Section top | Next |

Obtaining Information About a Single Sound Channel

You can use the SndChannelStatus function to obtain information about a single sound channel and about the status of a disk-based playback on that channel, if one exists. For example, you can use SndChannelStatus to determine if a channel is being used for play from disk, how many seconds of the sound have been played, and how many seconds remain to be played.

One of the parameters required by the SndChannelStatus function is a pointer to a sound channel status record, which you must allocate before calling SndChannelStatus . A sound channel status record has this structure:

TYPE SCStatus =
RECORD
    scStartTime:                    Fixed;          {starting time for play from disk}
    scEndTime:                      Fixed;          {ending time for play from disk}
    scCurrentTime:                  Fixed;          {current time for play from disk}
    scChannelBusy:                  Boolean;        {TRUE if channel is processing cmds}
    scChannelDisposed:              Boolean;        {reserved}
    scChannelPaused:                Boolean;        {TRUE if channel is paused}
    scUnused:                       Boolean;        {unused}
    scChannelAttributes:            LongInt;        {attributes of this channel}
    scCPULoad:                      LongInt;        {CPU load for this channel}
END;

The scStartTime , scEndTime , and scCurrentTime fields are 0 unless the Sound Manager is currently playing from disk through the specified channel. If a play from disk is occurring, the scStartTime and scEndTime fields reflect the starting and ending points of the play, defined in seconds; the scCurrentTime field indicates the number of seconds between the beginning of the sound on disk and the part of the sound currently being played. The Sound Manager sets the values of the scStartTime and scEndTime fields based on the values you set in an audio selection record. (See [link] for a description of the audio selection record.)

Note that because the Sound Manager might be playing only a selection of a sound, the scCurrentTime field does not reflect the number of seconds of sound play that have elapsed. To compute the number of seconds of sound play elapsed, you can subtract the value in the scStartTime field from that in the scCurrentTime field. However, because the Sound Manager updates the value of the scCurrentTime field only periodically, you should not rely on the accuracy of its value.

The scChannelBusy and scChannelPaused fields reflect whether a channel is processing commands and whether a channel is paused, respectively. After issuing a series of sound commands, you can use these fields to determine if the channel has finished processing all of the commands. If both scChannelBusy and scChannelPaused are FALSE , the Sound Manager has processed all of the channel's commands.

You can mask out certain values in the scChannelAttributes field to determine how a channel has been initialized.

CONST
    initPanMask         = $0003;        {mask for right/left pan values}
    initSRateMask       = $0030;        {mask for sample rate values}
    initStereoMask      = $00C0;        {mask for mono/stereo values}

The scCPULoad field previously reflected the percentage of CPU processing power used by the sound channel. However, this field is obsolete, and you should not rely on its value.

Listing 1-23 illustrates the use of the SndChannelStatus function. It defines a function that takes a sound channel pointer as a parameter and determines whether a disk-based playback on that channel is paused.

Listing 23 Determining whether a sound channel is paused

FUNCTION MyChannelIsPaused (chan: SndChannelPtr): Boolean;
VAR
    myErr:              OSErr;
    mySCStatus:         SCStatus;
BEGIN
    MyChannelIsPaused := FALSE;
    myErr := SndChannelStatus(chan, Sizeof(SCStatus), @mySCStatus);
    IF myErr = noErr THEN
        MyChannelIsPaused := mySCStatus.scChannelPaused;
END;

The function defined in Listing 1-23 simply reads the scChannelPaused field to see if the playback is currently paused.

In Sound Manager versions earlier than 3.0, pausing a sound channel by issuing a pauseCmd command does not change the scChannelPaused field. The scChannelPaused field is TRUE only if the Sound Manager is executing a disk-based playback on the channel and that playback is paused by the SndPauseFilePlay function. This problem is fixed in Sound Manager versions 3.0 and later.


© 1999 Apple Computer, Inc.

| Previous | Chapter contents | Chapter top | Section top | Next |